package com.cloudxingkong.dianyinke.Student.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.bean.IntegraldetailsEntity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by ningfei on 2016/4/6.
 */
public class IntegralDetailsAdapter extends BaseAdapter {
    private List<IntegraldetailsEntity.ObjBean.ExpendlistBean.ListBean>data;
    private Context context;
    public IntegralDetailsAdapter(List<IntegraldetailsEntity.ObjBean.ExpendlistBean.ListBean> data, Context context) {
        this.data = data;
        this.context = context;

    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.integral_details_item, null);
            holder = new ViewHolder();

            holder.tv_jfxq_yue = (TextView) convertView.findViewById(R.id.tv_jfxq_date);
            holder.tv_jfxq_type = (TextView) convertView.findViewById(R.id.tv_jfxq_type);
            holder.tv_jfxq_num = (TextView) convertView.findViewById(R.id.tv_jfxq_num);
            holder.tv_jfxq_sum = (TextView) convertView.findViewById(R.id.tv_jfxq_sum);//20个
            holder.tv_jfxq_pic = (ImageView) convertView.findViewById(R.id.tv_jfxq_pic);
            holder.tv_jfxq_zhuagtai = (TextView) convertView.findViewById(R.id.tv_jfxq_zhuagtai);
            holder.tvMonth = (TextView) convertView.findViewById(R.id.tvMonth);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String serverTime = data.get(position).getTime();//时间
        String ts = serverTime.substring(6,7);
        holder.tv_jfxq_yue.setText(ts);;
        holder.tvMonth.setText(serverTime.substring(8, 10)+"日");
        holder.tv_jfxq_type.setText(data.get(position).getName() +"" );//类型
        holder.tv_jfxq_num.setText(data.get(position).getNum()+"支");//数量
        holder.tv_jfxq_sum.setText(data.get(position).getPoints()+"个");//剩余积分
        holder.tv_jfxq_zhuagtai.setText(data.get(position).getStatus() + "");//状态

        holder.tv_jfxq_pic.setTag(serverTime);

        if (holder.tv_jfxq_pic.getTag() != null && holder.tv_jfxq_pic.getTag().equals(serverTime)) {
            ImageLoader.getInstance().displayImage(data.get(position).getPic(),holder.tv_jfxq_pic);
        }
        return convertView;
    }
    private class ViewHolder{
            ImageView tv_jfxq_pic;
            TextView tv_jfxq_yue,tv_jfxq_type,tv_jfxq_num,tv_jfxq_sum,tv_jfxq_zhuagtai,tvMonth;
    }
}
